package com.zgc.zkinfo;

import com.zgc.cache.CuratorClientCache;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.CuratorFrameworkFactory.Builder;
import org.apache.curator.retry.RetryOneTime;

public class ZkCuratorClientFactory {

    private static final Builder builder = CuratorFrameworkFactory.builder()
            .retryPolicy(new RetryOneTime(3000));


    public static CuratorFramework builder(ZkConnectionInfo connection) {
        builder.connectString(connection.getHost());
        builder.connectionTimeoutMs(connection.getConnectionTimeoutMs());
        builder.sessionTimeoutMs(connection.getSessionTimeoutMs());
        CuratorFramework curatorClient = builder.build();
        CuratorClientCache.putCuratorClient(connection.getId(), curatorClient);
        return curatorClient;
    }
}
